import datetime

from pydantic import BaseModel, Field
from typing import Optional, List, Union

from module_admin.entity.vo.cms_driver_vo import OrderListOrderChild


class CarModel(BaseModel):
    # 必填
    id: Optional[int] = Field(None, primary_key=True)
    car_id: Optional[str] = Field(None, comment='车辆编码')
    car_number: Optional[str] = Field(None, comment='车牌号')
    car_department_id: Optional[str] = Field(None, comment='所属部门id')
    car_type: Optional[str] = Field(None, comment='车辆类型')
    car_model: Optional[str] = Field(None, comment='车辆型号')
    car_brand: Optional[str] = Field(None, comment='车辆品牌')
    car_team_id: Optional[str] = Field(None, comment='车队id')
    car_head: Optional[str] = Field(None, comment='车辆负责人')
    # 选填
    property_right: Optional[str] = Field(None, comment='产权（公有，私有）')
    state: Optional[int] = Field(None, comment='状态（0 停用，1 启用）')
    charging_type: Optional[str] = Field(None, comment='计费类型')
    energy_type: Optional[str] = Field(None, comment='能源类型（汽油，柴油，电）')
    buy_date: Optional[datetime.datetime] = Field(None, comment='购买日期')
    vin_no: Optional[str] = Field(None, comment='车架号')
    engine_o: Optional[str] = Field(None, comment='发动机号')
    car_image: Optional[str] = Field(None, comment='车牌照片')
    car_permit_image: Optional[str] = Field(None, comment='车牌证件')
    # 设备
    device_id: Optional[str] = Field(None, comment='设备id')
    remark: Optional[str] = Field(None, comment='备注')
    create_time: Optional[datetime.datetime] = Field(None, comment='创建时间')
    create_by: Optional[str] = Field(None, comment='创建人')
    update_time: Optional[datetime.datetime] = Field(None, comment='修改时间')
    update_by: Optional[str] = Field(None, comment='修改人')
    # 人员
    driver_id: Optional[str] = Field(None, comment='驾驶员id')
    # 新增2024-05-26
    seat_num: Optional[int] = Field(None, comment='核定座位')
    fixed_asset_code: Optional[str] = Field(None, comment='固定资产编号')
    car_number_color: Optional[str] = Field(None, comment='车牌颜色')


class CarModelAndFree(BaseModel):
    # 必填
    id: Optional[int] = Field(None, primary_key=True)
    car_id: Optional[str] = Field(None, comment='车辆编码')
    car_number: Optional[str] = Field(None, comment='车牌号')
    car_department_id: Optional[str] = Field(None, comment='所属部门id')
    car_type: Optional[str] = Field(None, comment='车辆类型')
    car_model: Optional[str] = Field(None, comment='车辆型号')
    car_brand: Optional[str] = Field(None, comment='车辆品牌')
    car_team_id: Optional[str] = Field(None, comment='车队id')
    car_head: Optional[str] = Field(None, comment='车辆负责人')
    # 选填
    property_right: Optional[str] = Field(None, comment='产权（公有，私有）')
    state: Optional[int] = Field(None, comment='状态（0 停用，1 启用）')
    charging_type: Optional[str] = Field(None, comment='计费类型')
    energy_type: Optional[str] = Field(None, comment='能源类型（汽油，柴油，电）')
    buy_date: Optional[datetime.datetime] = Field(None, comment='购买日期')
    vin_no: Optional[str] = Field(None, comment='车架号')
    engine_o: Optional[str] = Field(None, comment='发动机号')
    car_image: Optional[str] = Field(None, comment='车牌照片')
    car_permit_image: Optional[str] = Field(None, comment='车牌证件')
    # 设备
    device_id: Optional[str] = Field(None, comment='设备id')
    remark: Optional[str] = Field(None, comment='备注')
    create_time: Optional[datetime.datetime] = Field(None, comment='创建时间')
    create_by: Optional[str] = Field(None, comment='创建人')
    update_time: Optional[datetime.datetime] = Field(None, comment='修改时间')
    update_by: Optional[str] = Field(None, comment='修改人')
    # 人员
    driver_id: Optional[str] = Field(None, comment='驾驶员id')
    # 新增2024-05-26
    seat_num: Optional[int] = Field(None, comment='核定座位')
    fixed_asset_code: Optional[str] = Field(None, comment='固定资产编号')
    car_number_color: Optional[str] = Field(None, comment='车牌颜色')
    # 空闲状态
    car_state: Optional[str] = Field(None, comment='车辆状态 空闲，任务中')


class RealTimeMessage(BaseModel):
    # 基础信息
    car_now_location: Optional[str] = Field(None, comment='车辆当前位置')
    longitude: Optional[str] = Field(None, comment='经度')
    latitude: Optional[str] = Field(None, comment='维度')
    responsible_person: Optional[str] = Field(None, comment='责任人')
    driver_name: Optional[str] = Field(None, comment='驾驶员')
    order_id: Optional[str] = Field(None, comment='运单号')


class ArchivesMessage(BaseModel):
    id: Optional[int] = Field(None, primary_key=True)
    car_id: Optional[str] = Field(None, comment='车辆编码')
    car_number: Optional[str] = Field(None, comment='车牌号')
    car_department_id: Optional[str] = Field(None, comment='所属部门')  # 1
    car_type: Optional[str] = Field(None, comment='车辆类型')
    car_model: Optional[str] = Field(None, comment='车辆型号')
    car_brand: Optional[str] = Field(None, comment='车辆品牌')
    car_team_name: Optional[str] = Field(None, comment='车队名称')  # 2
    car_team_id: Optional[str] = Field(None, comment='车队id')  # 2
    car_head: Optional[str] = Field(None, comment='车辆负责人')
    seat_num: Optional[int] = Field(None, comment='核定座位')
    fixed_asset_code: Optional[str] = Field(None, comment='固定资产编号')
    car_number_color: Optional[str] = Field(None, comment='车牌颜色')
    device_mode: Optional[str] = Field(None, comment='设备模式')
    driver_id: Optional[str] = Field(None, comment='驾驶员id')
    # 选填
    property_right: Optional[str] = Field(None, comment='产权（公有，私有）')
    state: Optional[int] = Field(None, comment='状态（0 停用，1 启用）')
    charging_type: Optional[str] = Field(None, comment='计费类型')
    energy_type: Optional[str] = Field(None, comment='能源类型（汽油，柴油，电）')
    buy_date: Optional[datetime.datetime] = Field(None, comment='购买日期')
    vin_no: Optional[str] = Field(None, comment='车架号')
    engine_o: Optional[str] = Field(None, comment='发动机号')
    car_image: Optional[str] = Field(None, comment='车牌照片')
    car_permit_image: Optional[str] = Field(None, comment='车牌证件')
    # 设备
    car_device_no: Optional[str] = Field(None, comment='设备编号')  # 3
    device_id: Optional[str] = Field(None, comment='设备id')  # 3
    device_type: Optional[str] = Field(None, comment='设备模式')  # 3
    remark: Optional[str] = Field(None, comment='备注')


class StatsMessage(BaseModel):
    # 基础信息
    sum_mileage: Optional[float] = Field(None, comment='总里程')
    sum_order_num: Optional[int] = Field(None, comment='总任务数')
    sum_expenses: Optional[float] = Field(None, comment='总费用')

class OrderListMessageForQuery(BaseModel):
    # 基础信息
    driver_id_str: Optional[str] = Field(None, comment='司机id,dri_类型id')
    car_id_str: Optional[str] = Field(None, comment='车辆id,car_类型id')
    begin_time: Optional[datetime.datetime] = Field(None, comment='查询开始时间')
    end_time: Optional[datetime.datetime] = Field(None, comment='查询结束时间')


class OrderListMessage(BaseModel):
    # 基础信息
    reality_begin_time: Optional[datetime.datetime] = Field(None, comment='实际出车时间')
    reality_end_time: Optional[datetime.datetime] = Field(None, comment='实际回车时间')
    car_number: Optional[str] = Field(None, comment='车牌号')
    driver_name: Optional[str] = Field(None, comment='驾驶员姓名')

class CarModelAndDetails(BaseModel):
    # 基础信息
    id: Optional[int] = Field(None, primary_key=True)
    car_id: Optional[str] = Field(None, comment='车辆编码')
    car_number: Optional[str] = Field(None, comment='车牌号')
    car_device_no: Optional[str] = Field(None, comment='设备号')
    car_state: Optional[str] = Field(None, comment='车辆状态 空闲，任务中')
    real_time_message: Optional[RealTimeMessage] = Field(None, comment='实时信息')
    archives_message: Optional[ArchivesMessage] = Field(None, comment='档案信息')
    stats_message: Optional[StatsMessage] = Field(None, comment='统计信息')


class CarModelForPage(BaseModel):
    id: Optional[int] = Field(None, primary_key=True)
    car_id: Optional[str] = Field(None, comment='车辆编码')
    car_number: Optional[str] = Field(None, comment='车牌号')
    car_device_no: Optional[str] = Field(None, comment='车载设备号')
    car_location: Optional[str] = Field(None, comment='车辆位置')
    car_speed: Optional[str] = Field(None, comment='车辆速度')
    driver_name: Optional[str] = Field(None, comment='驾驶员')
    is_online: Optional[str] = Field(None, comment='是否在线 1在线 0不在线')


class CarForQuery(BaseModel):
    car_number: Optional[str] = Field(None, title="车牌号/车载设备号")
    state: Optional[int] = Field(None, title="状态")
    car_department_id: Optional[str] = Field(None, title="所属部门id")
    car_team_id: Optional[str] = Field(None, title="车队id")


class CarPageObject(CarForQuery):
    page_num: int
    page_size: int


class CrudCarResponse(BaseModel):
    is_success: bool
    message: str


class CarOrderList(BaseModel):
    id: Optional[int] = Field(None, primary_key=True)
    car_id: Optional[str] = Field(None, comment='车辆编码')
    car_number: Optional[str] = Field(None, comment='车牌号')
    order_list: Optional[List[OrderListOrderChild]] = Field(None, comment='用车申请集合')


class CarSimpleModel(BaseModel):
    # 必填
    id: Optional[int] = Field(None, primary_key=True)
    car_id: Optional[str] = Field(None, comment='车辆编码')
    car_number: Optional[str] = Field(None, comment='车牌号')
    car_department_name: Optional[str] = Field(None, comment='所属部门')
    car_type: Optional[str] = Field(None, comment='车辆类型')
    car_model: Optional[str] = Field(None, comment='车辆型号')
    car_brand: Optional[str] = Field(None, comment='车辆品牌')

class CarModelForRecordList(BaseModel):
    # 必填
    id: Optional[int] = Field(None, primary_key=True)
    car_id: Optional[str] = Field(None, comment='车辆编码')
    car_number: Optional[str] = Field(None, comment='车牌号')
    car_department_id: Optional[str] = Field(None, comment='所属部门id')
    car_type: Optional[str] = Field(None, comment='车辆类型')
    car_model: Optional[str] = Field(None, comment='车辆型号')
    car_brand: Optional[str] = Field(None, comment='车辆品牌')
    car_team_id: Optional[str] = Field(None, comment='车队id')
    car_head: Optional[str] = Field(None, comment='车辆负责人')
    # 选填
    property_right: Optional[str] = Field(None, comment='产权（公有，私有）')
    state: Optional[int] = Field(None, comment='状态（0 停用，1 启用）')
    charging_type: Optional[str] = Field(None, comment='计费类型')
    energy_type: Optional[str] = Field(None, comment='能源类型（汽油，柴油，电）')
    buy_date: Optional[datetime.datetime] = Field(None, comment='购买日期')
    vin_no: Optional[str] = Field(None, comment='车架号')
    engine_o: Optional[str] = Field(None, comment='发动机号')
    car_image: Optional[str] = Field(None, comment='车牌照片')
    car_permit_image: Optional[str] = Field(None, comment='车牌证件')
    # 设备
    device_id: Optional[str] = Field(None, comment='设备id')
    remark: Optional[str] = Field(None, comment='备注')
    create_time: Optional[datetime.datetime] = Field(None, comment='创建时间')
    create_by: Optional[str] = Field(None, comment='创建人')
    update_time: Optional[datetime.datetime] = Field(None, comment='修改时间')
    update_by: Optional[str] = Field(None, comment='修改人')
    # 人员
    driver_id: Optional[str] = Field(None, comment='驾驶员id')
    # 新增2024-05-26
    seat_num: Optional[int] = Field(None, comment='核定座位')
    fixed_asset_code: Optional[str] = Field(None, comment='固定资产编号')
    car_number_color: Optional[str] = Field(None, comment='车牌颜色')
    # add
    driver_name: Optional[str] = Field(None, comment='驾驶员姓名')
    phone: Optional[str] = Field(None, comment='电话号')

